<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        const p1 = new Promise((resolve,reject) => {
            try{
                console.log("请求数据A");
                // throw new Error("A错误")
                setTimeout(() => {
                    console.log("请求A结束...");
                    resolve("A数据")
                }, 3000);
            }
            catch(e){
                reject (e.message)
            }
        });

        const p2 = new Promise((resolve,reject) => {
            try{
                console.log("请求数据B");
                // throw new Error("B错误")
                setTimeout(() => {
                    console.log("请求B结束...");
                    resolve("B数据")
                }, 1500);
            }
            catch(e){
                reject (e.message)
            }
        });

        const p3 = new Promise((resolve,reject) => {
            try{
                console.log("请求数据C");
                // throw new Error("C错误")
                setTimeout(() => {
                    console.log("请求C结束...");
                    resolve("C数据")
                }, 1000);
            }
            catch(e){
                reject (e.message)
            }
        });

        /*
        Promise.race方法：
            -监听的promise实例中改变状态最快的那一个，无论是成功还是失败
            -race的返回值和最快的这个实例保持一致
        */ 

        const result = Promise.race([p1,p2,p3]);
        console.log("result",result);
    </script>
</body>
</html>